package com.apps.ftapp.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/5/4.
 */

public class DateUtil {


    /**
     * 时间戳转换成日期格式字符串
     *
     * @param seconds   精确到秒的字符串
     * @param formatStr
     * @return
     */
    public static String timeStamp2Date(String seconds, String format) {
        try {
            if (seconds == null || seconds.isEmpty() || seconds.equals("null")) {
                return "";
            }
            if (format == null || format.isEmpty()) {
                format = "yyyy-MM-dd HH:mm:ss";
            }
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return sdf.format(new Date(Long.valueOf(seconds + "000")));
        } catch (Exception e) {
            return "";
        }
    }


    /**
     * 将long类型转化为Date
     *
     * @param str
     * @return
     * @throws ParseException
     */
    public static String LongToDare(String str) {
        try {
            long time = Long.parseLong(str);
            SimpleDateFormat defaultFormat = new SimpleDateFormat("yyyy-MM-dd");
            return defaultFormat.format(new Date(time * 1000));
        } catch (Exception e) {
            return "";
        }
    }

}
